package com.gitee.wsl.transform.encode.pinyin.trie.handler

import com.gitee.wsl.transform.encode.pinyin.trie.Emit
import com.gitee.wsl.transform.encode.pinyin.trie.PayloadEmit

/**
 * Convenience wrapper class that delegates every method to a
 * [StatefulPayloadEmitHandler].
 */
class StatefulPayloadEmitDelegateHandler(private val handler: StatefulEmitHandler) : StatefulPayloadEmitHandler<String> {


    override fun emit(emit: PayloadEmit<String>): Boolean {
        val newEmit = Emit(emit.start, emit.end, emit.keyword)
        return handler.emit(newEmit)
    }


    override val emits: List<PayloadEmit<String>>
        get() {
            val emits: List<Emit> = this.handler.emits
            return Companion.asEmits(
                emits
            )
        }

    companion object {
        private fun asEmits(emits: Collection<Emit>): List<PayloadEmit<String>> {
            val result = ArrayList<PayloadEmit<String>>()
            for (emit in emits) {
                result.add(PayloadEmit<String>(emit.start, emit.end, emit.keyword, null))
            }
            return result
        }
    }
}
